package com.ruoyi.project.module.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.paper.domain.Paper;
import com.ruoyi.project.module.paper.service.IPaperService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 文章 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-12
 */
@Controller
@RequestMapping("/module/paper")
public class PaperController extends BaseController
{
    private String prefix = "module/paper";
	
	@Autowired
	private IPaperService paperService;
	
	@RequiresPermissions("module:paper:view")
	@GetMapping()
	public String paper()
	{
	    return prefix + "/paper";
	}
	
	/**
	 * 查询文章列表
	 */
	@RequiresPermissions("module:paper:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Paper paper)
	{
		startPage();
        List<Paper> list = paperService.selectPaperList(paper);
		return getDataTable(list);
	}
	
	/**
	 * 新增文章
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存文章
	 */
	@RequiresPermissions("module:paper:add")
	@Log(title = "文章", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Paper paper)
	{		
		return toAjax(paperService.insertPaper(paper));
	}

	/**
	 * 修改文章
	 */
	@GetMapping("/edit/{paperId}")
	public String edit(@PathVariable("paperId") Integer paperId, ModelMap mmap)
	{
		Paper paper = paperService.selectPaperById(paperId);
		mmap.put("paper", paper);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存文章
	 */
	@RequiresPermissions("module:paper:edit")
	@Log(title = "文章", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Paper paper)
	{		
		return toAjax(paperService.updatePaper(paper));
	}
	
	/**
	 * 删除文章
	 */
	@RequiresPermissions("module:paper:remove")
	@Log(title = "文章", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(paperService.deletePaperByIds(ids));
	}







	
}
